package com.mine.springmvc.thread;

// 测试stop
//1.
//2.设置一个标志位
//3.不要使用stop 或者
public class TestStop implements Runnable{

    boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"...run....thread....."+i++);
        }
    }

    public void stop(){
        this.flag = false;
    }


    public static void main(String[] args) throws InterruptedException {
        TestStop testStop = new TestStop();

        new Thread(testStop,"线程1").start();

        new Thread(testStop,"线程2").start();

        System.out.println("主线程5休眠五秒后，开始关闭子线程");
        Thread.sleep(5000);

        testStop.stop();
    }
}
